package com.dt76.smallloanbackenduser.controller.xiaohao;

import com.dt76.smallloanbackenduser.pojo.xiaohao.ApprovalLoan;
import com.dt76.smallloanbackenduser.pojo.xiaohao.BorrowOrder;
import com.dt76.smallloanbackenduser.remote.xiaohao.ApprovalLoanRemote;
import com.dt76.smallloanbackenduser.remote.xiaohao.BorrowOrderRemote;
import com.dt76.smallloanbackenduser.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.UUID;

@Controller
public class ApprovalLoanController {

    @Resource
    private ApprovalLoanRemote approvalLoanRemote;

    @Resource
    private BorrowOrderRemote borrowOrderRemote;

    @RequestMapping("/LoanRegistration/regist")
    @ResponseBody
    public Boolean LoanRegistration(ApprovalLoan approvalLoan,String boID) {
        boolean flag = false;
        BorrowOrder borrowOrder = borrowOrderRemote.qryByID(Integer.parseInt(boID));
        borrowOrder.setBoType("已放款");
        approvalLoan.setBoId(Integer.parseInt(boID));
        //生成银行凭证号
        String s = UUID.randomUUID().toString().replace("-", "").toLowerCase();
        approvalLoan.setAlTransactionNumber(s);
        //生成流水号
        int day = DateUtils.getDayNum();
        String s1 = day + "0" + boID;
        approvalLoan.setAlSerialNum(Long.parseLong(s1));
        //当前时间
        int i = approvalLoanRemote.addApproveLoan(approvalLoan);
        int i1 = borrowOrderRemote.modifyBorrowOrderType(borrowOrder);
        if (i > 0 & i1 > 0) {
            flag = true;
        }
        return flag;
    }
}
